using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class ToggleBtn : Toggle
{
    private Image bg;
    private Text text;

    private Image[] texs;

    protected override void Start()
    {
        base.Start();
        texs = transform.GetComponentsInChildren<Image>();
        text = transform.Find("Text").GetComponent<Text>();

        var colors = this.colors;
        colors.highlightedColor = StaticData.blue;
        this.colors = colors;

        this.toggleTransition = ToggleTransition.None;
        this.targetGraphic = transform.Find("Background").GetComponent<Image>();

        OnValueChange(isOn);
        this.onValueChanged.AddListener(OnValueChange);
    }

    public override void OnPointerEnter(PointerEventData eventData)
    {
        base.OnPointerEnter(eventData);
        if (!isOn)
            ChangeColor(StaticData.blue);
    }

    public override void OnPointerExit(PointerEventData eventData)
    {
        base.OnPointerExit(eventData);
        if (!isOn)
            ChangeColor(Color.white);
    }

    public void OnValueChange(bool isOn)
    {
        var color = isOn ? StaticData.blue : Color.white;
        ChangeColor(color);
    }


    private void ChangeColor(Color color)
    {
        foreach (var item in texs)
            item.color = color;

        text.color = color;
    }

}
